Skip to content

Conversation

o-santi
Copy link
Contributor

@o-santi o-santi commented Oct 7, 2025

What kind of change does this PR introduce?

Fix both storage and postgrest to not mutate external httpx client, given it is shared, by instead keeping their own copy of their parameters to pass into the request call. In order to properly manipulate URLs without mutation, I've decided to add the yarl dependency, which returns a new object upon path manipulation.

For the postgrest library, I've also decided to factor out all of the parameters that go into a request in a RequestConfig object, for it is very easy to miss a spot otherwise. I've had to change the tests to account for this. However, I think this greatly simplifies most of the libraries, as 99% of the code does not need to be async/sync, and can be stated only once in a further rewrite.

Additional context

Should fix #1245.

instead, use `yarl.URL` to parse and manipulate the URL in a stateless
way, by returning a new url when paths are appended
@o-santi o-santi requested a review from grdsdev October 7, 2025 16:29
@o-santi
Copy link
Contributor Author

o-santi commented Oct 7, 2025

I do think letting the httpx client be passed in was a mistake in general, for it adds way too much ambiguity on how parameters are merged. For instance, base_url should be entirely ignored if set in httpx, while the other parameters should be additive in general.

@coveralls
Copy link

coveralls commented Oct 7, 2025

Pull Request Test Coverage Report for Build 18322053654

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 57 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.03%) to 93.906%

Files with Coverage Reduction New Missed Lines %
src/postgrest/base_client.py 1 92.0%
src/supabase_functions/_sync/functions_client.py 2 97.06%
src/supabase_functions/_async/functions_client.py 2 97.06%
src/postgrest/utils.py 2 93.75%
src/postgrest/_sync/client.py 3 93.33%
src/postgrest/_async/client.py 3 93.33%
src/postgrest/_sync/request_builder.py 9 92.44%
src/postgrest/_async/request_builder.py 9 92.44%
src/postgrest/base_request_builder.py 26 91.29%
Totals Coverage Status
Change from base Build 18285122346: 0.03%
Covered Lines: 8752
Relevant Lines: 9320

💛 - Coveralls

Copy link
Contributor

@silentworks silentworks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will pull this code down and test against my local codebase.

@silentworks
Copy link
Contributor

I do think letting the httpx client be passed in was a mistake in general, for it adds way too much ambiguity on how parameters are merged. For instance, base_url should be entirely ignored if set in httpx, while the other parameters should be additive in general.

It was either this or passing every parameter that httpx expects as a config parameter which felt like duplication work. Let's discuss in a new issue if you have another approach you think would work better.

@o-santi
Copy link
Contributor Author

o-santi commented Oct 7, 2025

I will pull this code down and test against my local codebase.

Thank you, please let me know of the results.

It was either this or passing every parameter that httpx expects as a config parameter which felt like duplication work.

The problem is that it is still happening, headers and base_url are such examples of arguments that can be set on both, and are ambiguous as to what setting both means. Furthermore, RequestConfig is basically a configuration class for httpx, which we might decide to just use directly instead. Setting things on it is much easier as we can assign immutable semantics, instead of httpx's mutable API, which is horrible for sharing configuration. I believe the only way forward is to expand something like RequestConfig into all libraries, and pass it around with immutable semantics, ditching the httpx client argument.

@o-santi
Copy link
Contributor Author

o-santi commented Oct 7, 2025

Just noticed that this problem is not only on these two libraries, functions also has it. realtime does not accept an httpx client, while auth accepts it but does store its own url and headers.

@o-santi o-santi changed the title fix: do not mutate httpx client inside storage and postgrest fix: do not mutate httpx client inside storage, postgrest and functions Oct 7, 2025
@silentworks
Copy link
Contributor

@o-santi I'm getting an error while using these changes in my test setup locally. The error is below.

Request URL is missing an 'http://' or 'https://' protocol.

Copy link
Contributor

@silentworks silentworks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async/SyncBucketActionsMixin class is missing the base_url and only has the path as the URL hence the error above. This needs to be updated to match the Async/SyncStorageBucketAPI use of base_url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants